package y24.m3.lanqiao14;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class Test2 {
    public static void main(String[] args) {
        int num = 1;
        int count = 0;
        int i = 1;
        while(count < 2023) {
            if (mod(i)){
                count++;
                num = i;
                System.out.println( count + ":" + num);
            }
            i++;
        }
        System.out.println(num);
    }

    private static boolean mod(int i) {
        int num = i;
        int sum = 0;
        while(num > 0){
            sum += num%10;
           num /= 10;
        }
        if (modNum(i,sum)){
            return false;
        }
        num = num(i,2);
        if (modNum(i,num)){
            return false;
        }
        num = num(i,8);
        if (modNum(i,num)){
            return false;
        }
        num = num(i,16);
        if (modNum(i,num)){
            return false;
        }
        return true;
    }

    private static int num(int i, int n) {
        Stack<Integer> stack = new Stack<>();
        while (i > 0){
            int r = i % n;
            if (r>10){
                stack.push(ch(r));
            }else {
                stack.push(r);
            }
            i/=n;
        }
        return n(stack);
    }

    private static int n(Stack<Integer> stack) {
        int sum = 0;
        for (Integer num : stack) {
            sum += num;
        }
        return sum;
    }

    private static boolean modNum(int i, int n) {
        if (i % n == 0){
            return false;
        }
        return true;
    }

    private static int ch_num(char c){
        Map<Character,Integer> ch = new HashMap<>();
        ch.put('a',10);
        ch.put('b',11);
        ch.put('c',12);
        ch.put('d',13);
        ch.put('e',14);
        ch.put('f',15);
        return ch.get(c);
    }
    private static int ch(int num){
        char[] ch = {'a','b','c','d','e','f'};
        return ch_num(ch[num-10]);
    }

}
